package com.shop.common.enums;

import lombok.Getter;

/**
 * 是否类型
 */
@Getter
public enum TrueFalseEnum {

    TRUE(1, "是", true),
    FALSE(0, "否", false),
    ;

    private int code;
    private String name;
    private boolean flag;

    TrueFalseEnum(int code, String name, boolean flag) {
        this.code = code;
        this.name = name;
        this.flag = flag;
    }

    public static TrueFalseEnum val(int code) {
        for (TrueFalseEnum trueFalseEnum : TrueFalseEnum.values()) {
            if(trueFalseEnum.code == code) {
                return trueFalseEnum;
            }
        }
        return null;
    }

    public static TrueFalseEnum val(boolean flag) {
        for (TrueFalseEnum trueFalseEnum : TrueFalseEnum.values()) {
            if(trueFalseEnum.flag == flag) {
                return trueFalseEnum;
            }
        }
        return null;
    }
}
